﻿using Newtonsoft.Json.Linq;
using Sunny.UI.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Microsoft.VisualBasic.ApplicationServices;
using Traceability.Commont.Domains;
using System.Text.Json;

namespace Butcher.winform.EnterpriseForms
{
    public partial class UserLogin : Form
    {
        public UserLogin()
        {
            InitializeComponent();
        }

        private void uiButton1_Click(object sender, EventArgs e)
        {
            string url = @"http://localhost:5021/api/Trace/UserLogin";
            HttpClient client = new HttpClient();
            Users us = new Users();
            us.UserName = UserNamed.Text;
            us.Pwd = UserPwds.Text;
            var sh = 0;
            var content = new StringContent(JsonSerializer.Serialize<Users>(us));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
            JObject info = JObject.Parse(result);
            var saaa = result;
            saaa = info["messges"].Value<string>();
            if (saaa != null)
            {
                sh = 1;
                MessageBox.Show("登录成功");
                Main main = new Main();
                main.Hide();
                main.ShowDialog();
                //SearchClient departmentview = new SearchClient();
                //this.Hide();
                //departmentview.ShowDialog();
            }
            else
            {
                sh = 0;
                MessageBox.Show("登录失败");
            }
        }

    }
}
